// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import { createInstance, updateToken } from '@/utils/apiUtil'

Vue.config.productionTip = false
Vue.prototype.$http = createInstance()
updateToken(Vue.prototype.$http)
// 自定义本应用的出错拦截器
Vue.prototype.$http.interceptors.response.use(response => response, error => {
  let statusCode = error.response.status
  switch (statusCode) {
    case 404:
      window.alert('router to 404')
      /*
      router.push({
        path: '/404'
      }) */
      break
    default:
      window.alert('出错了:' + statusCode)
      break
  }
  return Promise.reject(error)
})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  template: '<App/>',
  components: { App }
})
